table.ps.lastinsert = SELECT LAST_INSERT_ID()

alert.table_name			= ALERT
alert.field.alert_index		= ALERT_INDEX
alert.field.alertid			= ALERTID
alert.field.alertref		= ALERTREF
alert.field.scanid			= SCANID
alert.field.pluginid		= PLUGINID
alert.field.alert			= ALERT
alert.field.risk			= RISK
alert.field.reliability		= RELIABILITY
alert.field.description		= DESCRIPTION
alert.field.uri				= URI
alert.field.param			= PARAM
alert.field.attack			= ATTACK
alert.field.otherinfo		= OTHERINFO
alert.field.solution		= SOLUTION
alert.field.reference		= REFERENCE
alert.field.evidence		= EVIDENCE
alert.field.cweid			= CWEID
alert.field.wascid			= WASCID
alert.field.historyid		= HISTORYID
alert.field.sourcehistoryid	= SOURCEHISTORYID
alert.field.sourceid = SOURCEID
alert.ps.addalertindex			= CREATE INDEX ALERT_INDEX ON ALERT (SOURCEHISTORYID)
alert.ps.addalertref			= ALTER TABLE ALERT ADD COLUMN ALERTREF VARCHAR(256) DEFAULT ''
alert.ps.addattack				= ALTER TABLE ALERT ADD COLUMN ATTACK VARCHAR(32768) DEFAULT ''
alert.ps.addcweid				= ALTER TABLE ALERT ADD COLUMN CWEID INT DEFAULT -1
alert.ps.addwascid				= ALTER TABLE ALERT ADD COLUMN WASCID INT DEFAULT -1
alert.ps.addevidence			= ALTER TABLE ALERT ADD COLUMN EVIDENCE VARCHAR(16777216) DEFAULT ''
alert.ps.addsourcehistoryid		= ALTER TABLE ALERT ADD COLUMN SOURCEHISTORYID INT DEFAULT 0
alert.ps.addsourceid = ALTER TABLE ALERT ADD COLUMN SOURCEID INT DEFAULT 0
alert.ps.addsourceidindex = CREATE INDEX INDEX_ALERT_SOURCEID ON ALERT (SOURCEID)
alert.ps.delete					= DELETE FROM ALERT WHERE ALERTID = ?
alert.ps.deleteall				= DELETE FROM ALERT
alert.ps.read					= SELECT * FROM ALERT WHERE ALERTID = ? LIMIT 1
alert.ps.lastinsert				= SELECT LAST_INSERT_ID()
alert.ps.getalertsforhistoryid	= SELECT * FROM ALERT WHERE SOURCEHISTORYID = ?
alert.ps.getalertsforsession	= SELECT ALERTID FROM ALERT INNER JOIN SCAN ON ALERT.SCANID = SCAN.SCANID WHERE SESSIONID = ?
alert.ps.getallalertids			= SELECT ALERTID FROM ALERT
alert.ps.insert					= INSERT INTO ALERT (SCANID, PLUGINID, ALERT, RISK, RELIABILITY, DESCRIPTION, URI, PARAM, ATTACK, OTHERINFO, \
SOLUTION, REFERENCE, EVIDENCE, CWEID, WASCID, HISTORYID, SOURCEHISTORYID, SOURCEID, ALERTREF) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
alert.ps.update				= UPDATE ALERT SET ALERT = ?, RISK = ?, RELIABILITY = ?, DESCRIPTION = ?, URI = ?, PARAM = ?, ATTACK = ?,\
OTHERINFO = ?, SOLUTION = ?, REFERENCE = ?, EVIDENCE = ?, CWEID = ?, WASCID = ?, SOURCEHISTORYID = ? WHERE  ALERTID = ?
alert.ps.updatehistoryid		= UPDATE ALERT SET HISTORYID = ?, SOURCEHISTORYID = ? WHERE ALERTID = ?

context.table_name					= CONTEXT_DATA
context.field.contextid 			= CONTEXTID
context.field.data					= DATA
context.field.dataid				= DATAID
context.field.type 					= TYPE
context.ps.createtable		= CREATE CACHED TABLE CONTEXT_DATA (DATAID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), \
CONTEXTID INT NOT NULL, TYPE INT NOT NULL, DATA VARCHAR(8192) DEFAULT '')
context.ps.read						= SELECT * FROM CONTEXT_DATA WHERE DATAID = ?
context.ps.insert					= INSERT INTO CONTEXT_DATA (CONTEXTID, TYPE, DATA) VALUES (?, ?, ?)
context.ps.lastinsert				= SELECT LAST_INSERT_ID()
context.ps.delete					= DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ? AND DATA = ?
context.ps.deletealldataforcontext = DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ?
context.ps.deletealldataforcontexttype = DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ?
context.ps.alldata					= SELECT * FROM CONTEXT_DATA
context.ps.alldataforcontext		= SELECT * FROM CONTEXT_DATA WHERE  CONTEXTID = ?
context.ps.alldataforcontexttype	= SELECT * FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ?


history.table_name				= HISTORY
history.field.historyid			= HISTORYID
history.field.sessionid			= SESSIONID
history.field.histtype			= HISTTYPE
history.field.method			= METHOD
history.field.uri				= URI
history.field.statuscode		= STATUSCODE
history.field.timesentmillis	= TIMESENTMILLIS
history.field.timeelapsedmillis	= TIMEELAPSEDMILLIS
history.field.reqheader			= REQHEADER
history.field.reqbody			= REQBODY
history.field.resheader			= RESHEADER
history.field.resbody			= RESBODY
history.field.tag				= TAG
history.field.note				= NOTE
history.field.responsefromtargethost = RESPONSEFROMTARGETHOST
history.ps.containsuri		= SELECT HISTORYID FROM HISTORY WHERE URI = ? AND  METHOD = ? AND REQBODY = ? AND SESSIONID = ? AND HISTTYPE = ? LIMIT 1
history.ps.delete			= DELETE FROM HISTORY WHERE HISTORYID = ?
history.ps.deletesession	= DELETE FROM HISTORY WHERE SESSIONID = ?
history.ps.deletetemp		= DELETE FROM HISTORY WHERE HISTTYPE = ?
history.ps.deletetype		= DELETE FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE = ?
history.ps.gethistoryids	= SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? ORDER BY HISTORYID
history.ps.gethistoryidsinctypes	= SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE IN ({0}) ORDER BY HISTORYID
history.ps.gethistoryidsnottypes	= SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE NOT IN ({0}) ORDER BY HISTORYID
# problem here, or just not picking up right props?
history.ps.lastindex		= SELECT HISTORYID FROM HISTORY ORDER BY HISTORYID DESC LIMIT 1
history.ps.lastinsert		= SELECT LAST_INSERT_ID()
history.ps.read				= SELECT * FROM HISTORY WHERE HISTORYID = ? LIMIT 1 
history.ps.setnote			= UPDATE HISTORY SET NOTE = ? WHERE HISTORYID = ?
history.ps.insertstd		= INSERT INTO HISTORY (SESSIONID, HISTTYPE, TIMESENTMILLIS, TIMEELAPSEDMILLIS, METHOD, URI, REQHEADER,\
REQBODY, RESHEADER, RESBODY, TAG, STATUSCODE, NOTE, RESPONSEFROMTARGETHOST) VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ?, ?, ?, ?, ?)
history.ps.insertnost		= INSERT INTO HISTORY (SESSIONID, HISTTYPE, TIMESENTMILLIS, TIMEELAPSEDMILLIS, METHOD, URI, REQHEADER,\
REQBODY, RESHEADER, RESBODY, TAG, NOTE, RESPONSEFROMTARGETHOST) VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ? , ?, ?, ?)
history.ps.addtag			= ALTER TABLE HISTORY ADD COLUMN TAG VARCHAR(32768) DEFAULT ''
history.ps.addnote			= ALTER TABLE HISTORY ADD COLUMN NOTE VARCHAR(1048576) DEFAULT ''
history.ps.addrespfromtarget	= ALTER TABLE HISTORY ADD COLUMN RESPONSEFROMTARGETHOST BOOLEAN DEFAULT FALSE
history.ps.setrespfromtarget	= UPDATE TABLE_NAME SET RESPONSEFROMTARGETHOST = TRUE
# TODO default 16777216 too big? But might not need? Maybe will :/
history.ps.changereqsize		= ALTER TABLE TABLE_NAME ALTER COLUMN REQBODY VARBINARY(?)
history.ps.changerespsize		= ALTER TABLE TABLE_NAME ALTER COLUMN RESBODY VARBINARY(?)

param.table_name			= PARAM
param.field.paramid			= PARAMID
param.field.site			= SITE
param.field.type			= TYPE
param.field.name			= NAME
param.field.used			= USED
param.field.flags			= FLAGS
param.field.vals			= VALS
param.ps.addtable			= CREATE TABLE PARAM (PARAMID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), SITE VARCHAR(32768) NOT NULL, \
TYPE VARCHAR(32768) NOT NULL, NAME VARCHAR(32768) NOT NULL, USED INT NOT NULL, FLAGS VARCHAR(32768) NOT NULL, VALS VARCHAR(8388608) NOT NULL)
param.ps.read				= SELECT * FROM PARAM WHERE  PARAMID = ?
param.ps.insert				= INSERT INTO PARAM (SITE, TYPE, NAME, USED, FLAGS, VALS) VALUES (?, ?, ?, ?, ?, ?)
param.ps.lastinsert			= SELECT LAST_INSERT_ID()
param.ps.update				= UPDATE PARAM SET USED = ?, FLAGS = ?, VALS = ? WHERE PARAMID = ?
param.ps.getall				= SELECT * FROM PARAM

scan.table_name				= SCAN
scan.field.scanid			= SCANID
scan.field.scanname			= SCANNAME
scan.field.scantime			= SCANTIME
scan.field.sessionid		= SESSIONID
scan.ps.read				= SELECT * FROM SCAN WHERE SCANID = ?
scan.ps.insert				= INSERT INTO SCAN (SESSIONID, SCANNAME) VALUES (?, ?)
scan.ps.getlatestscan		= SELECT * FROM SCAN WHERE SCANID = (SELECT MAX(B.SCANID) FROM SCAN AS B)
scan.ps.lastinsert			= SELECT LAST_INSERT_ID()

session.field.sessionid		= SESSIONID
session.field.sessionname	= SESSIONNAME
session.field.lastaccess	= LASTACCESS
session.ps.insert			= INSERT INTO SESSION (SESSIONID, SESSIONNAME, LASTACCESS) VALUES (?, ?, NOW())
session.ps.list				= SELECT * FROM SESSION
session.ps.update			= UPDATE SESSION SET SESSIONNAME = ?, LASTACCESS = NOW() WHERE SESSIONID = ?

sessionurl.table_name		= SESSION_URL
sessionurl.field.type		= TYPE
sessionurl.field.url		= URL
sessionurl.field.urlid		= URLID

# TODO fix
sessionurl.ps.createtable		= CREATE TABLE SESSION_URL (URLID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), \
TYPE INT NOT NULL, URL VARCHAR(8192) DEFAULT '')
sessionurl.ps.read				= SELECT * FROM SESSION_URL WHERE URLID = ?
sessionurl.ps.insert			= INSERT INTO SESSION_URL (TYPE, URL) VALUES (?, ?)
sessionurl.ps.lastinsert		= SELECT LAST_INSERT_ID()
sessionurl.ps.deleteurls		= DELETE FROM SESSION_URL WHERE TYPE = ? AND URL = ?
sessionurl.ps.deleteurlsfortype	= DELETE FROM SESSION_URL WHERE TYPE = ?
sessionurl.ps.geturlsfortype	= SELECT * FROM SESSION_URL WHERE TYPE = ?

structure.ps.createtable		= CREATE TABLE STRUCTURE (STRUCTUREID BIGINT(20) NOT NULL AUTO_INCREMENT, \
SESSIONID BIGINT(20) NOT NULL, PARENTID BIGINT(20) NOT NULL, HISTORYID INT(11) DEFAULT NULL, NAME TEXT NOT NULL, \
NAMEHASH BIGINT(20) NOT NULL, URL TEXT NOT NULL, METHOD VARCHAR(10) NOT NULL, PRIMARY KEY (STRUCTUREID))
structure.ps.find			= SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND NAMEHASH = ? AND METHOD = ?
structure.ps.read			= SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND STRUCTUREID = ?				
structure.ps.insert			= INSERT INTO STRUCTURE (SESSIONID, PARENTID, HISTORYID, NAME, NAMEHASH, URL, METHOD) VALUES (?, ?, ?, ?, ?, ?, ?)
structure.ps.lastinsert		= SELECT LAST_INSERT_ID()
structure.ps.getchildren	= SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?
structure.ps.getchildcount	= SELECT COUNT(*) FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?

tag.table_name				= TAG
tag.field.historyid			= HISTORYID
tag.field.tag				= TAG
tag.field.tagid				= TAGID
tag.ps.createtable			= CREATE TABLE TAG (TAGID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), HISTORYID BIGINT NOT NULL, TAG VARCHAR(1024) DEFAULT '')"));
tag.ps.read					= SELECT * FROM TAG WHERE TAGID = ?
tag.ps.insert				= INSERT INTO TAG (HISTORYID, TAG) VALUES (?, ?)
tag.ps.lastinsert			= SELECT LAST_INSERT_ID()
tag.ps.delete				= DELETE FROM TAG WHERE HISTORYID = ? AND TAG = ?
tag.ps.gettagsforhid		= SELECT * FROM TAG WHERE HISTORYID = ?
tag.ps.deletetagsforhid		= DELETE FROM TAG WHERE HISTORYID = ?
tag.ps.getalltags			= SELECT DISTINCT TAG FROM TAG ORDER BY TAG
